<link href="/classico/public/assets/back-end/css/product-type/add.css"
      rel="stylesheet" type="text/css"/>
<div class="system-messages">
    <ul>
        <?php
        $messages = $this->messages;
        foreach ($messages as $message) :
            ?>
            <li><?= $message ?></li>
        <?php
        endforeach
        ?>
    </ul>
</div>
<?php
/** @var ProductTypePOJO $productTypePOJO */
$productTypePOJO = $this->productTypePOJO;
?>
<div class="admin-input-form-wrap">
    <form method="post">
        <div id="basic-info" class="admin-input-form">
            <table>
                <tr>
                    <td><label for="name">Name</label></td>
                    <td>
                        <input id="name" type="text" name="name"
                               value="<?= $productTypePOJO == null ?
                                   $this->name : $productTypePOJO->Name ?>"/>
                    </td>
                </tr>
                <tr>
                    <td><label for="description">Description</label></td>
                    <td>
                        <textarea id="description" name="description"
                                  spellcheck="false"><?= $productTypePOJO == null ?
                                $this->description : $productTypePOJO->Description ?></textarea>
                    </td>
                </tr>
            </table>
            <input type="hidden" name="isPost" value=""/>
        </div>
    </form>
</div>
<script type="text/javascript">
    function submitForm(task) {
        var name = $('#name').val().trim();
        var description = $('#description').val().trim();
        if (!name || !description) {
            var content = '';
            if (!name) {
                content += 'Name, ';
            }
            if (!description) {
                content += 'Description, ';
            }
            content = content.substr(0, content.length - 2);
            content += ' cannot be blank!';

            var messagesBlock = $('.system-messages > ul');
            messagesBlock.html('');
            messagesBlock.append('<li>' + content + '</li>');
        } else {
            var form = $('.admin-input-form-wrap > form');
            form.append('<input type="hidden" name="task" value="' + task + '"/>');
            form.attr('action', location.href);
            form.submit();
        }
    }

    $('#tool-btn-apply.enabled-tool-btn').click(function () {
        var task = 'apply';
        submitForm(task);
    });

    $('#tool-btn-applynclose.enabled-tool-btn').click(function () {
        var task = 'apply-and-close';
        submitForm(task);
    });

    $('#tool-btn-applynnew.enabled-tool-btn').click(function () {
        var task = 'apply-and-new';
        submitForm(task);
    });
</script>